<template>
  <div class="head">
    <div class="tit">
      <button class="tex1">特价业务汇总</button>
    </div>
    <div class="line" />
    <el-row>
      <el-col :span="24">
        <div class="title1">
          <el-form ref="form" :rules="rules" style="display: flex;flex-wrap: wrap;margin-top: 24px;justify-content: space-between;" :model="form" label-width="80px">
            <el-form-item prop="Time" style="margin-left: 0;" class="text" label="日期">
              <el-date-picker v-model="form.Time" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" style="width: 718px" @change="changeTime" />
            </el-form-item>
            <el-form-item prop="collectType" class="text" label="时间汇总">
              <el-select v-model="form.collectType" placeholder="请选择" style="width: 286px;">
                <el-option label="按天" value="1" />
                <el-option label="按年" value="2" />
              </el-select>
            </el-form-item>
            <el-form-item class="text" label="展示级别">
              <el-select v-model="form.displayLevel" class="input" placeholder="请选择" style="width: 286px;">
                <el-option label="网点" value="1" />
                <el-option label="承包区" value="2" />
              </el-select>
            </el-form-item>
            <div>
              <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
                <elbutton :obj="form" @dj="khClear" />
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div class="title1">
          <el-form ref="form1" style="display: flex;justify-content: space-between;flex-wrap: wrap;" :model="form" label-width="80px">
            <div style="display: flex;justify-content: space-between;flex-wrap: wrap;width:800px">
              <el-form-item class="text" label="网点名称">
                <el-select v-model="form.networkName" class="input" placeholder="辽宁盘锦公司" style="width: 286px;" :disabled="true">
                  <el-option label="辽宁盘锦公司" value="1" />
                </el-select>
              </el-form-item>
              <el-form-item class="text" label="承包区名">
                <el-select v-model="form.contractAreaNameId" class="input" placeholder="请选择" style="width: 286px;">
                  <el-option v-for="item in ShowCoverAreaList" :key="item.id" :label="item.networkName" :value="item.id" />
                </el-select>
              </el-form-item>
            </div>
            <div>
              <el-form-item>

                <el-button @click="onSubmit"><i class="el-icon-upload2" />导出</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <elltable :loading="loading" :data="tableData" :th="th">
          <template v-slot:before-columns>
            <el-table-column v-if="tableData.length>0" label="序号" :index="table_index" type="index" width="50" align="center" />
          </template>

        </elltable>
        <div style="display: flex;justify-content: space-between;margin-top: 51px;">
          <div class="title2" />
          <div class="block" style="display: flex; justify-content: flex-end">
            <pagination :current-page="current" :page-size="10" :total="+total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
          </div>
        </div>

      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getCityId, getProvinceList } from '@/api/dashboard'
import { ShowCoverAreaApi, SpecialPriceApi } from '@/api/HqFinancePanel'

export default {

  components: {},
  data() {
    return {
      rules: {
        Time: [
          { required: true, message: '请选择日期', trigger: 'change' }
        ],
        collectType: [
          { required: true, message: '请选择时间汇总', trigger: 'change' }
        ]
      },
      th: [],
      loading: false,
      id: '1',
      ProvinceList: [], // 省
      cityList: [], // 市
      value: '',
      form: {
        networkName: '',
        collectType: '',
        contractAreaNameId: '',
        displayLevel: '',
        endTime: '',
        pageDate: {
          pageNum: 1,
          pageSize: 10
        },
        startTime: ''
      },
      mxForm: {
        destinationProvince: '',
        destinationCity: ''
      },
      tableData: [],
      current: 0, // 页数
      pages: 0, // 条数
      total: 0, // 总数
      ShowCoverAreaList: [] // 承包区列表
    }
  },

  computed: {},

  created() {
    this.getProvince()
    this.ShowCoverArea()
  },

  methods: {
    handleSizeChange(val) {
      this.form.pageDate.pageSize = val
      this.onSubmit()
    },
    handleCurrentChange(val) {
      this.form.pageDate.pageNum = val
      this.onSubmit()
    },
    // 获取省
    getProvince() {
      getProvinceList().then((res) => {
        if (res.code === 200) {
          this.ProvinceList = res.data
        }
      })
    },
    // 获取省的id
    provinceChange(value) {
      this.mxForm.destinationProvince = value.province
      this.getCity(value.pid)
    },
    getCity(pid) {
      getCityId(pid).then((res) => {
        if (res.code === 200) {
          this.cityList = res.data
        }
      })
    },
    // 选择时间
    changeTime(value) {
      this.form.startTime = value[0]
      this.form.endTime = value[1]
    },
    // 承包区
    async ShowCoverArea() {
      const res = await ShowCoverAreaApi()
      this.ShowCoverAreaList = res.data
    },
    // 序号
    table_index(index) {
      return (this.form.pageDate.pageNum - 1) * this.form.pageDate.pageSize + index + 1
    },
    // 查询
    async onSubmit() {
      this.$refs.form.validate(async valid => {
        if (valid) {
          this.loading = true
          const res = await SpecialPriceApi(this.form)
          this.loading = false

          if (res.code == 200) {
            this.tableData = res.data.list.data
            this.total = res.data.list.total
            this.current = res.data.list.current
            this.pages = res.data.list.pages
            this.th = res.data.fields
          } else {
            this.tableData = []
            this.total = 0
            this.current = 1
            this.pages = 10
          }
        } else {
          return false
        }
      })
    },
    // changeLevel() {
    //   this.tableData = []
    // },
    // 重置
    khClear(aaa) {
      this.form = aaa
    }
  }
}

</script>
<style
  scoped
  lang="scss"
>
.tit {
  display: flex;

  .tex1 {
    margin-right: 48px;
    font-size: 16px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;
    background: #fff;
    border: 1px #fff solid;
  }

  .active {
    font-family: Source Han Sans CN;
    font-weight: 700;
    color: #2087d0;
    position: relative;
  }

  .active::before {
    position: absolute;
    content: "";
    width: 62px;
    height: 2px;
    background: #2087d0;
    border-radius: 1px;
    bottom: -20px;
    left: 50%;
    transform: translate(-50%);
  }
}

.head {
  padding: 30px;
}

.title {
  font-size: 16px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
  margin-top: 20px;
}

.line {
  height: 1px;
  background: #d8d8d8;
  border-radius: 1px;
  margin-top: 19px;
}

.title1 {
  .text {
    font-size: 18px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;

    .input {
      width: 286px;
      height: 36px;
      background: #ffffff;
      border-radius: 4px;
    }

    .input1 {
      width: 708px;
      height: 36px;
      background: #ffffff;
      border: 1px solid #b4b4b4;
      border-radius: 4px;
    }
  }
}

.title2 {
  font-size: 18px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
}
</style>
